from selenium import webdriver
import sys
import json
import os
from time import sleep

driver = webdriver.Chrome()

f = open('inner.txt', 'a+', encoding='UTF-8')


for num in range(1, 34):
    driver.get("http://www.aotesoft.com/ch/NewsList.asp?SortID=14&Page=" + str(num))
    driver.maximize_window()
    allA = driver.find_elements_by_xpath('//*[@id="pageBody"]/div[2]/div[1]/a')
    length = len(allA)
    for i in range(1, length + 1):
        driver.find_element_by_xpath('//*[@id="pageBody"]/div[2]/div[1]/a[' + str(i) + ']').click()
        sleep(0.2)
        title = driver.find_element_by_xpath('//*[@id="pageBody"]/div[2]/div[1]').text
        font = driver.find_element_by_xpath('//*[@id="pageBody"]/div[2]/div[2]').text.split('来源')[0].split('发布时间：')[1]
        f.write('### ' + title + '\n' + font + '\n\n')
        f.flush()
        driver.back()

driver.close()
f.flush()
f.close()